const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

let input_arr = []
rl.on('line', function (line) {
  input_arr.push(line)
}
);

rl.on('close', function () {
let count = parseInt(input_arr[0])
let weight_arr = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2]
let is_all_passed = true;

for(let i = 0; i < count; i++){
    let id_no = input_arr[i+1]
    let result = 0;
    for(let j = 0; j < 17; j++){
        result+=id_no[j] * weight_arr[j]
    }
    result = result % 11
    let check_arr = ['1','0','x','9','8','7','6','5','4','3','2']
    if(id_no[17] !== check_arr[result]){
        is_all_passed = false
        console.log(id_no);
    }
}
if(is_all_passed === true){
    console.log('All passed');
}
})